import maya.cmds as mc

def sphereDeriver(spherename='L_shoulder_dv'):
    mc.polySphere(n=spherename+'_geo')
    meshshape=mc.listRelatives(spherename+'_geo',s=True)[0]
    mc.createNode('closestPointOnMesh',n=spherename+'_cpom')
    
    meshMatrix=str(meshshape)+'.worldMatrix[0]'
    meshout=str(meshshape)+'.outMesh'
    geoshape=mc.listRelatives(spherename+'_geo',s=True)[0]
    mc.connectAttr(meshout,spherename+'_cpom.inMesh')
    
    folliclename=spherename+'_follicleshape'
    follicleparentname=spherename+'_follicle'
    mc.createNode('follicle',n=folliclename)
    follicleparent=mc.listRelatives(folliclename,p=True)[0]
    mc.rename(follicleparent,follicleparentname)
    mc.connectAttr(meshMatrix,str(folliclename)+'.inputWorldMatrix')
    mc.connectAttr(meshout,str(folliclename)+'.inputMesh')
    mc.connectAttr(str(folliclename)+'.outTranslate',follicleparentname+'.translate')
    mc.connectAttr(str(folliclename)+'.outRotate',follicleparentname+'.rotate')
    mc.setAttr(str(folliclename)+'.parameterU',0.5)
    mc.setAttr(str(folliclename)+'.parameterV',0.5)
    
    mc.select(cl=True)
    mc.spaceLocator(n=spherename+'_baseloc')
    mc.setAttr(spherename+'_baseloc.visibility',0)
    mc.parent(spherename+'_baseloc',spherename+'_geo')
    mc.select(cl=True)
    mc.spaceLocator(n=spherename+'_loc')
    mc.group(spherename+'_loc',n=spherename+'_loc_grp')
    mc.pointConstraint(spherename+'_follicle',spherename+'_loc_grp',mo=False)
    mc.aimConstraint(spherename+'_baseloc',spherename+'_loc_grp',mo=False,n='templeaim')
    mc.delete(spherename+'_follicle','templeaim')
    
    mc.select(cl=True)
    mc.spaceLocator(n=spherename+'_dvloc')
    mc.setAttr(spherename+'_dvloc.visibility',0)
    mc.parentConstraint(spherename+'_loc',spherename+'_dvloc',mo=False)
    mc.parent(spherename+'_dvloc',spherename+'_geo')
    mc.connectAttr(spherename+'_dvloc.translate',spherename+'_cpom.inPosition')
    
    
    mc.group(em=True,n=spherename+'_bridge')
    mc.addAttr(spherename+'_bridge',ln='parameter_U',h=False,k=True)
    mc.setAttr(spherename+'_bridge'+'.'+'parameter_U',k=True,cb=False)
    mc.addAttr(spherename+'_bridge',ln='parameter_V',h=False,k=True)
    mc.setAttr(spherename+'_bridge'+'.'+'parameter_V',k=True,cb=False)
    
    mc.connectAttr(str(spherename+'_cpom')+'.result.parameterU',spherename+'_bridge'+'.'+'parameter_U')
    mc.connectAttr(str(spherename+'_cpom')+'.result.parameterV',spherename+'_bridge'+'.'+'parameter_V')
      
    mc.group(spherename+'_geo',spherename+'_loc_grp',spherename+'_bridge',n=spherename+'_grp')